<?php
namespace app\admin\service;


use app\common\enum\order\PayStatus as PayStatusEnum;
use app\common\enum\order\Status as OrderStatusEnum;

use app\common\library\helper;
use app\store\model\Order as OrderModel;
use think\Model;
use think\Session;
use think\Db;
class Order extends Model
{

    protected $name='yonghui_customer';



    /**
     * 获取录客总数 (可指定某天)
     */
    public function getPayOrderTotal($startDate = null, $endDate = null){
        if (!is_null($startDate) && !is_null($endDate)) {
            $filter['createTime'] = [
                ['>=', strtotime($startDate)],
                ['<', strtotime($endDate) + 86400],
            ];
        }
        return $this->getOrderTotal($filter);
    }


    /**
     * 获取客户总数量
     * @param array $filter
     * @return int|string
     * @throws \think\Exception
     */
    private function getOrderTotal($filter = []){
       //根据登录人类型获取相应数据
        $type=Session::get('yoshop_adminuser')['user']['type'];
        if($type==1){
            //平台

        }elseif($type==2){
            //自营,获取其本身置业顾问录入的客户和所有的下属渠道公司的销售人员录入的客户
            $ids=[];
            $companyInfos=Db::name('yonghui_company')->where(['upId'=>Session::get('yoshop_adminuser')['user']['company_id']])->field('id,upId')->select();
            if($companyInfos){
                foreach($companyInfos as $k=>$v){
                    $ids[]=$v['id'];
                }
            }
            $ids[]=Session::get('yoshop_adminuser')['user']['company_id'];
            $filter['sourceId']=['in',$ids];
        }else{
            $filter['sourceId']=['=',Session::get('yoshop_adminuser')['user']['company_id']];
        }
        if(!empty($serach['search'])){
            $filter['name|circle']=['like','%'.$serach['search'].'%'];
        }
        return $this->where($filter)
            ->count();
    }


}